<?php
/**
 * View helper to generate links for a &lt;ul&gt; using &lt;li&gt;&lt;a&gt; to switch languages
 */
class Zend_View_Helper_LanguageMenu extends Zend_View_Helper_Abstract
{
    /**
     * Generates &lt;li&gt;&lt;a&gt; elements used to switch language
     * @param string $extraClass applied on all li
     * @param string $firstClass applied on first li only
     * @return string &lt;li&gt;&lt;a&gt;
     */
    public function LanguageMenu($extraClass = '', $firstClass = '')
    {
        $options = Zend_Registry::get('Zend_Application_Options');
        $locale = Zend_Registry::get('Zend_Locale');
        if ($firstClass) {
            $firstClass .= ' ';
        }
        $result = '';
        foreach ($options['locale'] as $l) {
            if ($l === $locale->toString()) {
                continue;
            }

            $result .= '<li'
            . ($extraClass ? ' class="' . $firstClass . $extraClass . '" ' : '')
            . '><a '
            . 'href="/session/language?language=' . urlencode($l) . '">' . htmlentities(ucfirst($l))
            . '</a></li>'
            . "\n";

            $firstClass = '';
        }
        return $result;
    }
}